package net.ibizsys.eclipse.studio.file;

import java.util.HashMap;
import java.util.Map;

import net.ibizsys.eclipse.studio.console.Console;
import net.ibizsys.eclipse.studio.xml.IBizFile;

/**
 * 
 * @author <a href='http://www.weibo.com/xjtoo' target='_blank'>Enmaai</a>
 */
public class IBizFileFactory
{
	private static Map<String, BaseFileBuilder> map = new HashMap<String, BaseFileBuilder>();

	static
	{
		ControllerFileBuilder controllerFileBuilder = new ControllerFileBuilder();
		if (controllerFileBuilder.init())
		{
			map.put(controllerFileBuilder.getFileType(), controllerFileBuilder);
		} else
		{
			Console.println("无法初始化对象[ControllerFileBuilder]");
		}
		CtrlHandlerFileBuilder ctrlHandlerFileBuilder = new CtrlHandlerFileBuilder();
		if (ctrlHandlerFileBuilder.init())
		{
			map.put(ctrlHandlerFileBuilder.getFileType(), ctrlHandlerFileBuilder);
		} else
		{
			Console.println("无法初始化对象[CtrlHandlerFileBuilder]");
		}
		CtrlModelFileBuilder ctrlModelFileBuilder = new CtrlModelFileBuilder();
		if (ctrlModelFileBuilder.init())
		{
			map.put(ctrlModelFileBuilder.getFileType(), ctrlModelFileBuilder);
		} else
		{
			Console.println("无法初始化对象[CtrlModelFileBuilder]");
		}
		ServiceFileBuilder serviceFileBuilder = new ServiceFileBuilder();
		if (serviceFileBuilder.init())
		{
			map.put(serviceFileBuilder.getFileType(), serviceFileBuilder);
		} else
		{
			Console.println("无法初始化对象[ServiceFileBuilder]");
		}
		DAOFileBuilder dAOFileBuilder = new DAOFileBuilder();
		if (dAOFileBuilder.init())
		{
			map.put(dAOFileBuilder.getFileType(), dAOFileBuilder);
		} else
		{
			Console.println("无法初始化对象[DAOFileBuilder]");
		}
		EntityFileBuilder entityFileBuilder = new EntityFileBuilder();
		if (entityFileBuilder.init())
		{
			map.put(entityFileBuilder.getFileType(), entityFileBuilder);
		} else
		{
			Console.println("无法初始化对象[EntityFileBuilder]");
		}
		DEModelFileBuilder dEModelFileBuilder = new DEModelFileBuilder();
		if (dEModelFileBuilder.init())
		{
			map.put(dEModelFileBuilder.getFileType(), dEModelFileBuilder);
		} else
		{
			Console.println("无法初始化对象[DEModelFileBuilder]");
		}
		CodeListModelFileBuilder codeListModelFileBuilder = new CodeListModelFileBuilder();
		if (codeListModelFileBuilder.init())
		{
			map.put(codeListModelFileBuilder.getFileType(), codeListModelFileBuilder);
		} else
		{
			Console.println("无法初始化对象[CodeListModelFileBuilder]");
		}
		DEACModelFileBuilder dEACModelFileBuilder = new DEACModelFileBuilder();
		if (dEACModelFileBuilder.init())
		{
			map.put(dEACModelFileBuilder.getFileType(), dEACModelFileBuilder);
		} else
		{
			Console.println("无法初始化对象[DEACModelFileBuilder]");
		}
		DEDSModelFileBuilder dEDSModelFileBuilder = new DEDSModelFileBuilder();
		if (dEDSModelFileBuilder.init())
		{
			map.put(dEDSModelFileBuilder.getFileType(), dEDSModelFileBuilder);
		} else
		{
			Console.println("无法初始化对象[DEDSModelFileBuilder]");
		}
		DEDQModelFileBuilder dEDQModelFileBuilder = new DEDQModelFileBuilder();
		if (dEDQModelFileBuilder.init())
		{
			map.put(dEDQModelFileBuilder.getFileType(), dEDQModelFileBuilder);
		} else
		{
			Console.println("无法初始化对象[DEDQModelFileBuilder]");
		}
		DELogicModelFileBuilder dELogicModelFileBuilder = new DELogicModelFileBuilder();
		if (dELogicModelFileBuilder.init())
		{
			map.put(dELogicModelFileBuilder.getFileType(), dELogicModelFileBuilder);
		} else
		{
			Console.println("无法初始化对象[DELogicModelFileBuilder]");
		}
		WFModelFileBuilder wFModelFileBuilder = new WFModelFileBuilder();
		if (wFModelFileBuilder.init())
		{
			map.put(wFModelFileBuilder.getFileType(), wFModelFileBuilder);
		} else
		{
			Console.println("无法初始化对象[WFModelFileBuilder]");
		}
		WFVerModelFileBuilder wFVerModelFileBuilder = new WFVerModelFileBuilder();
		if (wFVerModelFileBuilder.init())
		{
			map.put(wFVerModelFileBuilder.getFileType(), wFVerModelFileBuilder);
		} else
		{
			Console.println("无法初始化对象[WFVerModelFileBuilder]");
		}

		JSControllerFileBuilder jsControllerFileBuilder = new JSControllerFileBuilder();
		if (jsControllerFileBuilder.init())
		{
			map.put(jsControllerFileBuilder.getFileType(), jsControllerFileBuilder);
		} else
		{
			Console.println("无法初始化对象[JSControllerFileBuilder]");
		}

		JSPFileBuilder jspFileBuilder = new JSPFileBuilder();
		if (jspFileBuilder.init())
		{
			map.put(jspFileBuilder.getFileType(), jspFileBuilder);
		} else
		{
			Console.println("无法初始化对象[JSPFileBuilder]");
		}

		JSPPartFileBuilder jspPartFileBuilder = new JSPPartFileBuilder();
		if (jspPartFileBuilder.init())
		{
			map.put(jspPartFileBuilder.getFileType(), jspPartFileBuilder);
		} else
		{
			Console.println("无法初始化对象[JSPPartFileBuilder]");
		}

		DEUIActionFileBuilder uiActionFileBuilder = new DEUIActionFileBuilder();
		if (uiActionFileBuilder.init())
		{
			map.put(uiActionFileBuilder.getFileType(), uiActionFileBuilder);
		} else
		{
			Console.println("无法初始化对象[DEUIActionFileBuilder]");
		}

		CtrlItemHandlerFileBuilder ctrlItemHandlerFileBuilder = new CtrlItemHandlerFileBuilder();
		if (ctrlItemHandlerFileBuilder.init())
		{
			map.put(ctrlItemHandlerFileBuilder.getFileType(), ctrlItemHandlerFileBuilder);
		} else
		{
			Console.println("无法初始化对象[CtrlItemHandlerFileBuilder]");
		}
	}

	/**
	 * 创建文件
	 * 
	 * @param baseFile
	 * @param filename
	 * @param pkgName
	 * @return
	 */
	public static boolean create(IBizFile baseFile)
	{
		if (map.containsKey(baseFile.getType().code()))
		{
			return map.get(baseFile.getType().code()).build(baseFile);
		}

		Console.println("无法获取文件[" + baseFile.getType().code() + "]重写对象");

		return false;
	}
}
